<?php
    class LEO
    {	
        var $id;
        var $status;
        var $nachname;
        var $vorname;
        var $titel;
        var $adel;
        var $geburtsdatum;
        var $email;
        var $tel;
        var $mobil;
        var $adresse;
        var $plz;
        var $ort;
        var $land;
        var $email_g;
        var $tel_g;
        var $mobil_g;
        var $adresse_g;
        var $plz_g;
        var $ort_g;
        var $land_g;
        var $aktiv;

        public static function getLeoFromString($string)
        {
            $LEO = new LEO();
            
            if(isset($string["id"]) && $string["id"] != "null")
                $LEO->id =  ($string["id"]);
            if(isset($string["status"]) && $string["status"] != "null")
                $LEO->status =  ($string["status"]);
            if(isset($string["nachname"]))
                $LEO->nachname = ($string["nachname"]);
            if(isset($string["vorname"]))
                $LEO->vorname =  ($string["vorname"]);
            if(isset($string["titel"]) && $string["titel"] != "null")
                $LEO->titel =  ($string["titel"]);
            if(isset($string["adel"]) && $string["adel"] != "null")
                $LEO->adel =  ($string["adel"]);
            if(isset($string["geburtsdatum"]) && $string["geburtsdatum"] != "null")
                $LEO->geburtsdatum =  ($string["geburtsdatum"]);
            if(isset($string["email"]) && $string["email"] != "null")
                $LEO->email =  ($string["email"]);
            if(isset($string["tel"]) && $string["tel"] != "null")
                $LEO->tel =  ($string["tel"]);
            if(isset($string["mobil"]) && $string["mobil"] != "null")
                $LEO->mobil =  ($string["mobil"]);
            if(isset($string["adresse"]) && $string["adresse"] != "null")
                $LEO->adresse =  ($string["adresse"]);
            if(isset($string["plz"]) && $string["plz"] != "null")
                $LEO->plz =  ($string["plz"]);
            if(isset($string["ort"]) && $string["ort"] != "null")
                $LEO->ort =  ($string["ort"]);
            if(isset($string["land"]) && $string["land"] != "null")
                $LEO->land =  ($string["land"]);
            if(isset($string["email_g"]) && $string["email_g"] != "null")
                $LEO->email_g =  ($string["email_g"]);
            if(isset($string["tel_g"]) && $string["tel_g"] != "null")
                $LEO->tel_g =  ($string["tel_g"]);
            if(isset($string["mobil_g"]) && $string["mobil_g"] != "null")
                $LEO->mobil_g =  ($string["mobil_g"]);
            if(isset($string["adresse_g"]) && $string["adresse_g"] != "null")
                $LEO->adresse_g =  ($string["adresse_g"]);
            if(isset($string["plz_g"]) && $string["plz_g"] != "null")
                $LEO->plz_g =  ($string["plz_g"]);
            if(isset($string["ort_g"]) && $string["ort_g"] != "null")
                $LEO->ort_g =  ($string["ort_g"]);
            if(isset($string["land_g"]) && $string["land_g"] != "null")
                $LEO->land_g =  ($string["land_g"]);
            if(isset($string["aktiv"]) && $string["aktiv"] != "null")
                $LEO->aktiv =  ($string["aktiv"]);

            return $LEO;
        }
        
        public function GetUpdateString($id, $password, $gcm)
        {
            $isFirst = true;
            $sql = "UPDATE leo set ";
            
            if(isset($this->adel) && $this->adel != "null")
            {
                $sql =  $sql . " adel = '$this->adel' ";
                $isFirst = false;
            }
            
            if(isset($this->adresse) && $this->adresse != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " adresse = '$this->adresse' ";
                $isFirst = false;
            }
            
            if(isset($this->adresse_g) && $this->adresse_g != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " adresse_g = '$this->adresse_g' ";
                $isFirst = false;
            }
            
            if(isset($this->aktiv) && $this->aktiv != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " aktiv = '$this->aktiv' ";
                $isFirst = false;
            }
            
            if(isset($this->email) && $this->email != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " email = '$this->email' ";
                $isFirst = false;
            }
            
            if(isset($this->email_g) && $this->email_g != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " email_g = '$this->email_g' ";
                $isFirst = false;
            }
            
            if(isset($this->geburtsdatum) && $this->geburtsdatum != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " geburtsdatum = '$this->geburtsdatum' ";
                $isFirst = false;
            }
            
            if(isset($this->land) && $this->land != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " land = '$this->land' ";
                $isFirst = false;
            }
            
            if(isset($this->land_g) && $this->land_g != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " land_g = '$this->land_g' ";
                $isFirst = false;
            }
            
            if(isset($this->mobil) && $this->mobil != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " mobil = '$this->mobil' ";
                $isFirst = false;
            }
            
            if(isset($this->mobil_g) && $this->mobil_g != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " mobil_g = '$this->mobil_g' ";
                $isFirst = false;
            }
            
            if(isset($this->nachname) && $this->nachname != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " nachname = '$this->nachname' ";
                $isFirst = false;
            }
            
            if(isset($this->ort) && $this->ort != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " ort = '$this->ort' ";
                $isFirst = false;
            }
            
            if(isset($this->ort_g) && $this->ort_g != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " ort_g = '$this->ort_g' ";
                $isFirst = false;
            }
            
            if(isset($this->plz) && $this->plz != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " plz = '$this->plz' ";
                $isFirst = false;
            }
            
            if(isset($this->plz_g) && $this->plz_g != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " plz_g = '$this->plz_g' ";
                $isFirst = false;
            }
            
            if(isset($this->status) && $this->status != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " status = '$this->status' ";
                $isFirst = false;
            }
            
            if(isset($this->tel) && $this->tel != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " tel = '$this->tel' ";
                $isFirst = false;
            }
            
            if(isset($this->tel_g) && $this->tel_g != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " tel_g = '$this->tel_g' ";
                $isFirst = false;
            }
            
            if(isset($this->titel) && $this->titel != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " titel = '$this->titel' ";
                $isFirst = false;
            }
            
            if(isset($this->vorname) && $this->vorname != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " vorname = '$this->vorname' ";
                $isFirst = false;
            }
            
            if(isset($password) && $password != "null")
            {        
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " password = '$password' ";
                $isFirst = false;
            }
            
            if(isset($gcm) && $gcm != "null")
            {
                if(!$isFirst)
                    $sql =  $sql . ", ";
                
                $sql =  $sql . " gcm_id = '$gcm' ";
                $isFirst = false;
            }
            
            $sql =  $sql . "WHERE id = $id";
            
            if($isFirst)
            {
                return false;
            }
            else
            {
                return $sql;
            }
        }
        
        public function GetInsertString()
        {
            $isFirst = true;
            $columns = "";
            $values = "";
            
            if(isset($this->adel) && $this->adel != "null")
            {
                $columns = $columns .  "adel";
                $values = $values .  "'$this->adel#";
                $isFirst = false;
            }
            
            if(isset($this->adresse) && $this->adresse != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "adresse";
                $values = $values .  "'$this->adresse'";
                
                $isFirst = false;
            }
            
            if(isset($this->adresse_g) && $this->adresse_g != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "adresse_g";
                $values = $values .  "'$this->adresse_g'";
                $isFirst = false;
            }
            
            if(isset($this->aktiv) && $this->aktiv != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "aktiv";
                $values = $values .  "'$this->aktiv'";
                $isFirst = false;
            }
            
            if(isset($this->email) && $this->email != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "email";
                $values = $values .  "'$this->email'";
                $isFirst = false;
            }
            
            
            if(isset($this->email_g) && $this->email_g != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "email_g";
                $values = $values .  "'$this->email_g'";
                $isFirst = false;
            }
            
            if(isset($this->geburtsdatum) && $this->geburtsdatum != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "geburtsdatum";
                $values = $values .  "'$this->geburtsdatum'";
                $isFirst = false;
            }
            
            if(isset($this->land) && $this->land != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "land";
                $values = $values .  "'$this->land'";
                $isFirst = false;
            }
            
            if(isset($this->land_g) && $this->land_g != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "land_g";
                $values = $values .  "'$this->land_g'";
                $isFirst = false;
            }
            
            if(isset($this->mobil) && $this->mobil != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "mobil";
                $values = $values .  "'$this->mobil'";
                $isFirst = false;
            }
            
            if(isset($this->mobil_g) && $this->mobil_g != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "mobil_g";
                $values = $values .  "'$this->mobil_g'";
                $isFirst = false;
            }
            
            if(isset($this->nachname) && $this->nachname != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "nachname";
                $values = $values .  "'$this->nachname'";
                $isFirst = false;
            }
            
            if(isset($this->ort) && $this->ort != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "ort";
                $values = $values .  "'$this->ort'";
                $isFirst = false;
            }
            
            if(isset($this->ort_g) && $this->ort_g != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "ort_g";
                $values = $values .  "'$this->ort_g'";
                $isFirst = false;
            }
            
            if(isset($this->plz) && $this->plz != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "plz";
                $values = $values .  "'$this->plz'";
                $isFirst = false;
            }
            
            if(isset($this->plz_g) && $this->plz_g != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "plz_g";
                $values = $values .  "'$this->plz_g'";
                $isFirst = false;
            }
            
            if(isset($this->status) && $this->status != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "status";
                $values = $values .  "'$this->status'";
                $isFirst = false;
            }
            
            if(isset($this->tel) && $this->tel != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "tel";
                $values = $values .  "'$this->tel'";
                $isFirst = false;
            }
            
            if(isset($this->tel_g) && $this->tel_g != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "tel_g";
                $values = $values .  "'$this->tel_g'";
                $isFirst = false;
            }
            
            if(isset($this->titel) && $this->titel != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "titel";
                $values = $values .  "'$this->titel'";
                $isFirst = false;
            }
            
            if(isset($this->vorname) && $this->vorname != "null")
            {
                if(!$isFirst)
                {
                    $columns = $columns .  ", ";
                    $values = $values .  ", ";
                }
                
                $columns = $columns .  "vorname";
                $values = $values .  "'$this->vorname'";
                $isFirst = false;
            }
                        
            if($isFirst)
                return false;
            else
            {
                return "INSERT INTO LEO
                        ($columns) VALUES ($values);";
            }
        }
    }
?>